package org.wuqi.microweb.util;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.crypto.SecretKey;
import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

/**
 * @author jjj
 * @program: earnest-money
 * @description:TODO
 * @date 2024-01-09 17:29:11
 */
public class JwtUtil {
    @Value("${jwtObject.secret}")
   private String key;
   public String createJwt(Map<String,Object> data,Integer minute) throws Exception{
       Date date = new Date();
       SecretKey secretKey = Keys.hmacShaKeyFor(key.getBytes(StandardCharsets.UTF_8));
       String compact = Jwts.builder().signWith(secretKey, SignatureAlgorithm.HS256).setExpiration(DateUtils.addMinutes(date, minute)).setId(UUID.randomUUID().toString().replaceAll("-", "")).addClaims(data).addClaims(data).compact();
       return compact;
   }
}
 
 